﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resto.CostControl.Core.Cache;
using Resto.CostControl.Core.Facade.MaterialModule.DataTransferObject;
using Resto.CostControl.Core.Domain.Model;
using System.ComponentModel.DataAnnotations;
using Resto.CostControl.Core.Enums;
using Resto.CostControl.Common.Consts;

namespace Resto.CostControl.Core.Facade.DishModule.DataTransferObject
{
    /// <summary>
    /// 菜肴配比项
    /// </summary>
    public class DishMaterialDTO
    {
        #region 构造函数

        public DishMaterialDTO()
        {

        }

        /// <summary>
        /// 根据输入的材料Id，自动生成该对象
        /// </summary>
        /// <param name="materialId"></param>
        public DishMaterialDTO(string materialId)
        {
            MaterialDTO materialDTO = MaterialDTOCache.Get(materialId);
            if (materialDTO != null)
            {
                this.MaterialId = materialDTO.ID;
                this.MaterialName = materialDTO.Name;
                this.MaterialType = materialDTO.Type;
                this.CategoryCode = materialDTO.CategoryCode;
                
                //if (materialDTO.IsSemiMaterial())
                //{
                //    this.RawMaterialId = materialDTO.RawMaterialId;
                //    this.RawMaterialName = materialDTO.RawMaterialName;
                //    this.SemiMaterialId = materialDTO.ID;
                //    this.SemiMaterialName = materialDTO.Name;
                //}
                //else
                //{
                //    this.RawMaterialId = materialDTO.ID;
                //    this.RawMaterialName = materialDTO.Name;
                //}
            }
        }


        #endregion

        #region 基本属性

        /// <summary>
        /// 品名Id
        /// </summary>
        public string MaterialId { get; set; }

        /// <summary>
        /// 品名名称
        /// </summary>
        public string MaterialName { get; set; }

        ///// <summary>
        ///// 原材料的Id
        ///// </summary>
        //public int RawMaterialId { get; set; }

        ///// <summary>
        ///// 原材料的名称（只读）
        ///// </summary>
        //public string RawMaterialName { get; internal set; }

        ///// <summary>
        ///// 半成品的Id
        ///// </summary>
        //public int SemiMaterialId { get; set; }

        ///// <summary>
        ///// 半成品的名称（只读）
        ///// </summary>
        //public string SemiMaterialName { get; internal set; }

        /// <summary>
        /// 品名价格(只读)
        /// </summary>
        public decimal CurrentPrice { get; set; }

        /// <summary>
        /// 是原材料，还是半成品(只读)
        /// </summary>        
        public MaterialType MaterialType { get; set; }

        /// <summary>
        /// 品名大类代码(只读)
        /// </summary>        
        public string CategoryCode { get; set; }

        /// <summary>
        /// 品名大类名称
        /// </summary>        
        public string CategoryName
        {
            get
            {
                return DictionaryVOArrayCache.GetDicNameByCode(DictionaryTypeConsts.String_MaterialCategory_Code, CategoryCode);
            }
        }

        /// <summary>
        /// 每份克重
        /// </summary>
        public decimal Weight { get; set; }

        #endregion

        #region 方法

        internal DishMaterial ToDishMaterial()
        {
            return new DishMaterial()
            {
                //MaterialID = this.SemiMaterialId > 0 ? this.SemiMaterialId : this.RawMaterialId,
                MaterialID = this.MaterialId,
                Weight = this.Weight,
            };
        }

        #endregion
    }
}
